console.log("starting...");

// import "./polyfills.js";
import "./ux/inert.js";

import {
  defer
} from "./util/functions.js";
import {
  gaEvent
} from "./util/ga.js";
import * as denylist from "./util/denylist.js";
import {
  earth
} from "./earth.js";
import {
  isAppContext,
  isDevContext,
  isIFrameContext,
  siteInstance,
  siteVersion
} from "./util/context.js";
// require("./clock").calibration({server: "/"}); /*calibration({fixed: "2015-11-24T00:00Z"});*/

import {
  utils,sharedStore,sessionStore
} from "./utils.js";


function launch(bridge = {}) {
  earth({
    bridge
  }).then(client => {
    window.earth = client;
    bridge.ready?.();
  });
}

function main() {

  if (isDevContext()) {
    console.log("dev mode enabled");
  }

  gaEvent("site_instance", siteInstance(), siteVersion());

  // work-around for iOS 10 bug: https://github.com/metafizzy/flickity/issues/457
  window.addEventListener("touchmove", () => {});

  if (isIFrameContext()) {
    gaEvent("iframe", document.referrer.split("/")[2] || document.referrer);
    if (denylist.matches(document.referrer)) {
      denylist.deny();
      return;
    }
  }

  if (isAppContext()) {
    window.main = bridge => defer(() => launch(bridge));
    return;
  }

  document.getElementById("failure_note").remove();

  launch( /*createLogBridge()*/ );

}


export {
  main,utils,sharedStore,sessionStore
};
